package com.ssm.web;

import com.ssm.Service.UserService;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

@WebServlet(name="RegisterServlet",urlPatterns = "/register")
public class RegisterServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        //解决接收参数中的中文乱码问题
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String email = request.getParameter("email");

        UserService userservice=new UserService();

        boolean register = userservice.register(name, password, email);
        if(register){
            response.sendRedirect(request.getContextPath()+ "/");
        }else{
            response.sendRedirect(request.getContextPath()+ "/jsp/404.jsp");
        }
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }
}
